package com.qiyi.player.wonder.plugins.scenetile.view
{
   import org.puremvc.as3.patterns.mediator.Mediator;
   import com.qiyi.player.wonder.plugins.scenetile.model.SceneTileProxy;
   import com.qiyi.player.wonder.plugins.scenetile.SceneTileDef;
   import com.qiyi.player.wonder.body.BodyDef;
   import org.puremvc.as3.interfaces.INotification;
   import com.qiyi.player.wonder.body.model.PlayerProxy;
   import com.qiyi.player.wonder.common.pingback.PingBack;
   import com.qiyi.player.wonder.common.pingback.PingBackDef;
   import com.qiyi.player.wonder.plugins.ad.ADDef;
   import com.qiyi.player.wonder.body.model.UserProxy;
   import com.qiyi.player.wonder.common.vo.UserInfoVO;
   
   public class SceneTileDetailsViewMediator extends Mediator
   {
      
      public function SceneTileDetailsViewMediator(param1:SceneTileDetailsView) {
         super(NAME,param1);
         this._sceneTileDetailsView = param1;
      }
      
      public static const NAME:String = "com.qiyi.player.wonder.plugins.scenetile.view.SceneTileDetailsViewMediator";
      
      private var _sceneTileProxy:SceneTileProxy;
      
      private var _sceneTileDetailsView:SceneTileDetailsView;
      
      override public function onRegister() : void {
         super.onRegister();
         this._sceneTileProxy = facade.retrieveProxy(SceneTileProxy.NAME) as SceneTileProxy;
         this._sceneTileDetailsView.addEventListener(SceneTileEvent.Evt_DetailsOpen,this.onSceneTileDetailsViewOpen);
         this._sceneTileDetailsView.addEventListener(SceneTileEvent.Evt_DetailsClose,this.onSceneTileDetailsViewClose);
      }
      
      override public function listNotificationInterests() : Array {
         return [SceneTileDef.NOTIFIC_ADD_STATUS,SceneTileDef.NOTIFIC_REMOVE_STATUS,BodyDef.NOTIFIC_RESIZE,BodyDef.NOTIFIC_CHECK_USER_COMPLETE,BodyDef.NOTIFIC_PLAYER_ADD_STATUS,BodyDef.NOTIFIC_PLAYER_SWITCH_PRE_ACTOR];
      }
      
      override public function handleNotification(param1:INotification) : void {
         var _loc5_:PlayerProxy = null;
         super.handleNotification(param1);
         var _loc2_:Object = param1.getBody();
         var _loc3_:String = param1.getName();
         var _loc4_:String = param1.getType();
         switch(_loc3_)
         {
            case SceneTileDef.NOTIFIC_ADD_STATUS:
               if(int(_loc2_) == SceneTileDef.STATUS_DETAILS_OPEN)
               {
                  _loc5_ = facade.retrieveProxy(PlayerProxy.NAME) as PlayerProxy;
                  if(_loc5_.curActor.movieInfo)
                  {
                     this._sceneTileDetailsView.setContent(_loc5_.curActor.movieInfo.infoJSON,_loc5_.curActor.albumInfo.albumInfoJSON);
                  }
                  PingBack.getInstance().userActionPing(PingBackDef.DETAIL);
                  sendNotification(ADDef.NOTIFIC_POPUP_OPEN);
               }
               this._sceneTileDetailsView.onAddStatus(int(_loc2_));
               break;
            case SceneTileDef.NOTIFIC_REMOVE_STATUS:
               if(int(_loc2_) == SceneTileDef.STATUS_DETAILS_OPEN)
               {
                  sendNotification(ADDef.NOTIFIC_POPUP_CLOSE);
               }
               this._sceneTileDetailsView.onRemoveStatus(int(_loc2_));
               break;
            case BodyDef.NOTIFIC_RESIZE:
               this._sceneTileDetailsView.onResize(_loc2_.w,_loc2_.h);
               break;
            case BodyDef.NOTIFIC_CHECK_USER_COMPLETE:
               this.onCheckUserComplete();
               break;
            case BodyDef.NOTIFIC_PLAYER_ADD_STATUS:
               this.onPlayerStatusChanged(int(_loc2_),true,_loc4_);
               break;
            case BodyDef.NOTIFIC_PLAYER_SWITCH_PRE_ACTOR:
               this._sceneTileProxy.removeStatus(SceneTileDef.STATUS_DETAILS_OPEN);
               break;
         }
      }
      
      private function onSceneTileDetailsViewOpen(param1:SceneTileEvent) : void {
         if(!this._sceneTileProxy.hasStatus(SceneTileDef.STATUS_DETAILS_OPEN))
         {
            this._sceneTileProxy.addStatus(SceneTileDef.STATUS_DETAILS_OPEN);
         }
      }
      
      private function onSceneTileDetailsViewClose(param1:SceneTileEvent) : void {
         if(this._sceneTileProxy.hasStatus(SceneTileDef.STATUS_DETAILS_OPEN))
         {
            this._sceneTileProxy.removeStatus(SceneTileDef.STATUS_DETAILS_OPEN);
         }
      }
      
      private function onPlayerStatusChanged(param1:int, param2:Boolean, param3:String) : void {
         if(param3 != BodyDef.PLAYER_ACTOR_NOTIFIC_TYPE_CUR)
         {
            return;
         }
         switch(param1)
         {
            case BodyDef.PLAYER_STATUS_ALREADY_LOAD_MOVIE:
            case BodyDef.PLAYER_STATUS_STOPED:
            case BodyDef.PLAYER_STATUS_FAILED:
               if(param2)
               {
                  this._sceneTileProxy.removeStatus(SceneTileDef.STATUS_DETAILS_OPEN);
               }
               break;
         }
      }
      
      private function onCheckUserComplete() : void {
         var _loc1_:UserProxy = facade.retrieveProxy(UserProxy.NAME) as UserProxy;
         var _loc2_:UserInfoVO = new UserInfoVO();
         _loc2_.isLogin = _loc1_.isLogin;
         _loc2_.passportID = _loc1_.passportID;
         _loc2_.userID = _loc1_.userID;
         _loc2_.userName = _loc1_.userName;
         _loc2_.userLevel = _loc1_.userLevel;
         _loc2_.userType = _loc1_.userType;
         this._sceneTileDetailsView.onUserInfoChanged(_loc2_);
      }
   }
}
